import {Notification} from 'element-ui'
require('./blob');

/**
 * Excel文件流导出到Excel文件
 * @param promise 请求结果
 * @param fileName 文件名
 */
export const excelStreamToFile=(promise,fileName)=>{
    promise.then(({data})=>{
        let link = document.createElement('a')
        let blob = new Blob([data],{type: 'application/octet-stream'});
        link.style.display = 'none'
        link.href = URL.createObjectURL(blob);
        link.setAttribute('download', fileName+'.xlsx')
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
        // Notification({title: '导出成功', message: '请下载文件！', type: 'success'});
    }).catch((data)=>{
        Notification({title: '导出失败', message: '原因：'+data, type: 'warning'});
    })

}